import java.io.*;
import java.util.Hashtable;
import java.util.Stack;

import org.antlr.runtime.*;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.Tree;
import org.antlr.stringtemplate.*;
import org.antlr.stringtemplate.language.*;

public class PythonASTReader {
	CommonTree root = null;
	public PythonASTReader(CommonTree tree){
		root = tree;
	}
	private void log(String s){
		System.out.println(s);
	}
	private Hashtable<String, Boolean> globalVariables = new Hashtable<String, Boolean>();
	
	public void printFunctions(){
		CommonTree currentCommonTree = root;
		Stack<Tree> trees = new Stack<Tree>();
		trees.push(currentCommonTree);
		while(trees.size() > 0 && (currentCommonTree = (CommonTree) trees.pop()) != null){
			if(currentCommonTree.getType() == PythonParser.FUNCTION_DEF){
				System.out.println("Found function with child number be " + currentCommonTree.getChildCount());
				System.out.println("Function name is:" + currentCommonTree.getChild(0).getText());
				System.out.println("Statement number is:" + currentCommonTree.getChild(
								currentCommonTree.getChildCount() - 1).getChildCount());
			}
			for (int i = 0; i < currentCommonTree.getChildCount(); i++) {
				trees.push((CommonTree) currentCommonTree.getChild(i));
			}
		}
	}
}
